package com.cxria.script

List getData(String xlsName){
    def execl = new SuperExecl()
    def workbook = execl.getWorkbook(xlsName)
    def cellValueClazzs = [String.class, Integer.class, Integer.class]
    def sheet = execl.getSheet(workbook, 0, cellValueClazzs)
    execl.getData(sheet, 1)
}

/*def data1 = getData('/home/xiefeihong/文档/video-0-17618.xlsx')
def data2 = getData('/home/xiefeihong/文档/video-0-6249.xlsx')
def data3 = getData('/home/xiefeihong/文档/video-0-3060.xlsx')
def data4 = getData('/home/xiefeihong/文档/video-0-498.xlsx')
def data5 = getData('/home/xiefeihong/文档/video-0-6.xlsx')

def data = []
data.addAll(data1)
data.addAll(data2)
data.addAll(data3)
data.addAll(data4)
data.addAll(data5)*/

/*def execl = new SuperExecl()
def xlsName = '/home/xiefeihong/文档/video.xlsx'
def workbook = execl.createWorkbook(xlsName)
def sheet = execl.createSheet(workbook, [fileName: 3000, fileSize: 3000, cutSize: 3000])
(1..data.size()).each { lineIndex ->
    def line = data[lineIndex]
    execl.writeLine(sheet, lineIndex, line)
}
execl.writeToFile(xlsName, workbook)*/

/*def qshellFile = '/home/xiefeihong/文档/qshell-result.txt'
def lines = new File(qshellFile).readLines()

for (def lineIndex = 0; lineIndex < lines.size() - 1; lineIndex++){
    def lineStr = lines[lineIndex]
    data.each { line ->
        if(line.size() > 0){
            def videoName = line[0]
            try{
                if(videoName && lineStr.startsWith(videoName)){
                    println videoName
                    lines.remove(lineIndex)
                    lineIndex --
                }
            } catch (e){
                println e.message
            }
        }
    }
}

qshellFile2 = '/home/xiefeihong/文档/qshell-result5.txt'
new File(qshellFile2).write(lines.join('\n'))*/

def cmdUtils = new CmdUtils()
String.metaClass.exec = {
    cmdUtils.execute(delegate)
}

def rootPath = '/usr/local/qshell'
def qshellListFile = new File("${rootPath}/qshell-result.txt")
def bigLines = qshellListFile.readLines()
def videoInfos = [:]
bigLines.each { line ->
    def lineInfo = line.split('\t')
    def videoNameInfo = lineInfo[0]
    def videoSize = lineInfo[1] as BigInteger
    videoInfos.put(videoNameInfo, videoSize)
}

def data = getData('/home/xiefeihong/文档/video.xlsx')
def va = new VideoAnalysis()

videoInfos.each { name, size ->
    data.each { line ->
        if (line.size() == 3) {
            def name2 = line[0]
            def size2 = line[2]
            if (size2 != '' && size2 < 10 && name == name2) {
                def (isFFprobe, tryIndex) = va.tryLine(name as String, size as BigInteger, '/home/xiefeihong/视频', 1024 * 1024 * 10 as int)
                println "${isFFprobe} ${tryIndex} ${name}"
            }
        }
    }
}